//
//  HYFileDownloadViewController.m
//  XPlayer
//
//  Created by liguoqing on 2023/9/8.
//

#import "HYFileDownloadViewController.h"
#import "HYFileDownloadViewModel.h"
#import "HYFileDownloadView.h"
#import "HYVideoRoomViewController.h"

@interface HYFileDownloadViewController ()

@property (nonatomic, strong) HYFileDownloadViewModel *viewModel;

@property (nonatomic, strong) HYFileDownloadView *downloadView;

@end

@implementation HYFileDownloadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
    [self bindSignal];
    [self loadData];
}

- (void)configUI
{
    self.navigationBarView.titleLabel.text = NSLocalizedString(@"我的下载", nil);
    [self.view addSubview:self.downloadView];
    [self.downloadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navigationBarView.mas_bottom);
        make.left.bottom.right.equalTo(self.view);
    }];
}

- (void)bindSignal
{
    @weakify(self);
    [self.viewModel.playSubject subscribeNext:^(HYVideoViewModel *viewModel) {
        @strongify(self);
        HYVideoRoomViewController *videoVC = [[HYVideoRoomViewController alloc]initWithViewModel:viewModel];
        [self.navigationController pushViewController:videoVC animated:YES];
    }];
}

- (void)loadData
{
    [self.viewModel loadData];
}

- (HYFileDownloadView *)downloadView
{
    if(!_downloadView){
        _downloadView = [[HYFileDownloadView alloc]initWithViewModel:self.viewModel];
    }
    return _downloadView;
}

- (HYFileDownloadViewModel *)viewModel
{
    if(!_viewModel){
        _viewModel = [[HYFileDownloadViewModel alloc]init];
    }
    return _viewModel;
}


@end
